package servicesImp.expertInfo;

import StaticFinal.CrudType;
import org.apache.shiro.SecurityUtils;
import util.JsonUtil;
import wt.entity.expertInfo.ExpertBase;
import wt.entity.expertInfo.LeaderCheck;
import wt.entity.expertInfo.LeaderCheckWithBLOBs;
import wt.entity.upms.Account;
import wt.staticData.ShortData;

import java.util.Date;

/**
 * 功能:
 * 作者: 洪世成
 * 日期: 2017/10/28
 * 版权所有: admin
 */
public class LeaderCheckUtil {

    /**
     * 管理员通过专家的插入申请
     *
     * @param newDate
     * @param tableName
     * @param expertId
     * @return
     */
    public static LeaderCheckWithBLOBs verifier1Insert(Object newDate, String tableName, ExpertBase expertBase) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = new LeaderCheckWithBLOBs();
        leaderCheckWithBLOBs.setNewData(JsonUtil.obj2Json(newDate));
        leaderCheckWithBLOBs.setTableName(tableName);
        leaderCheckWithBLOBs.setOperateType(CrudType.insert);
        leaderCheckWithBLOBs.setExpertId(expertBase.getId());
        leaderCheckWithBLOBs.setExpertName(expertBase.getName());
        leaderCheckWithBLOBs.setExpertIdCard(expertBase.getIdCard());
        Account acc = (Account) SecurityUtils.getSubject().getPrincipal();
        leaderCheckWithBLOBs.setVerifier1Id(acc.getStaffInfo().getId());
        leaderCheckWithBLOBs.setVerifier1IdCard(acc.getStaffInfo().getIdCard());
        leaderCheckWithBLOBs.setVerifier1Name(acc.getStaffInfo().getName());
        leaderCheckWithBLOBs.setVerifier1OperateDate(new Date());
        leaderCheckWithBLOBs.setWorkFlowStep((short) 2);
        leaderCheckWithBLOBs.setRecordRiseDate(new Date());
        return leaderCheckWithBLOBs;
    }

    /**
     * 管理员驳回专家的插入申请
     *
     * @param newDate
     * @param tableName
     * @param expertId
     * @return
     */
    public static LeaderCheckWithBLOBs verifier1InsertDisagree(Object newDate, String tableName, ExpertBase expertBase, String reason) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = verifier1Insert(newDate, tableName, expertBase);
        leaderCheckWithBLOBs.setWorkFlowStep(ShortData.s5);
        leaderCheckWithBLOBs.setWorkFlowStop(ShortData.s1);
        leaderCheckWithBLOBs.setOperateResult(ShortData.s0);
        leaderCheckWithBLOBs.setOperateReason(reason);
        return leaderCheckWithBLOBs;
    }

    /**
     * 管理员通过专家的修改申请
     *
     * @param oldDate
     * @param newDate
     * @param tableName
     * @param expertId
     * @return
     */
    public static LeaderCheckWithBLOBs verifier1Update(Object oldDate, Object newDate, String tableName,ExpertBase  expertBase) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = new LeaderCheckWithBLOBs();
        leaderCheckWithBLOBs.setOldData(JsonUtil.obj2Json(oldDate));
        leaderCheckWithBLOBs.setNewData(JsonUtil.obj2Json(newDate));
        leaderCheckWithBLOBs.setTableName(tableName);
        leaderCheckWithBLOBs.setOperateType(CrudType.update);
        leaderCheckWithBLOBs.setExpertId(expertBase.getId());
        leaderCheckWithBLOBs.setExpertName(expertBase.getName());
        leaderCheckWithBLOBs.setExpertIdCard(expertBase.getIdCard());
        Account acc = (Account) SecurityUtils.getSubject().getPrincipal();
        leaderCheckWithBLOBs.setVerifier1Id(acc.getStaffInfo().getId());
        leaderCheckWithBLOBs.setVerifier1IdCard(acc.getStaffInfo().getIdCard());
        leaderCheckWithBLOBs.setVerifier1Name(acc.getStaffInfo().getName());
        leaderCheckWithBLOBs.setVerifier1OperateDate(new Date());
        leaderCheckWithBLOBs.setWorkFlowStep((short) 2);

        leaderCheckWithBLOBs.setRecordRiseDate(new Date());
        return leaderCheckWithBLOBs;
    }

    /**
     * 管理员驳回专家的修改申请
     *
     * @param newDate
     * @param tableName
     * @param expertBase
     * @return
     */
    public static LeaderCheckWithBLOBs verifier1UpdateDisagree(Object oldData, Object newDate, String tableName, ExpertBase expertBase, String reason) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = verifier1Update(oldData, newDate, tableName, expertBase);
        leaderCheckWithBLOBs.setWorkFlowStep(ShortData.s5);
        leaderCheckWithBLOBs.setWorkFlowStop(ShortData.s1);
        leaderCheckWithBLOBs.setOperateResult(ShortData.s0);
        leaderCheckWithBLOBs.setOperateReason(reason);
        return leaderCheckWithBLOBs;
    }

    /**
     * 管理员通过专家的删除申请
     *
     * @param oldDate
     * @param tableName
     * @param expertBase
     * @return
     */
    public static LeaderCheckWithBLOBs verifier1Delete(Object oldDate, String tableName, ExpertBase expertBase) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = new LeaderCheckWithBLOBs();
        leaderCheckWithBLOBs.setOldData(JsonUtil.obj2Json(oldDate));
        leaderCheckWithBLOBs.setTableName(tableName);
        leaderCheckWithBLOBs.setOperateType(CrudType.delete);
        leaderCheckWithBLOBs.setExpertId(expertBase.getId());
        leaderCheckWithBLOBs.setExpertName(expertBase.getName());
        leaderCheckWithBLOBs.setExpertIdCard(expertBase.getIdCard());
        Account acc = (Account) SecurityUtils.getSubject().getPrincipal();
        leaderCheckWithBLOBs.setVerifier1Id(acc.getStaffInfo().getId());
        leaderCheckWithBLOBs.setVerifier1IdCard(acc.getStaffInfo().getIdCard());
        leaderCheckWithBLOBs.setVerifier1Name(acc.getStaffInfo().getName());
        leaderCheckWithBLOBs.setVerifier1OperateDate(new Date());
        leaderCheckWithBLOBs.setWorkFlowStep((short) 2);
        leaderCheckWithBLOBs.setRecordRiseDate(new Date());
        return leaderCheckWithBLOBs;
    }

    /**
     * 管理员驳回专家的删除申请
     *
     * @param oldData
     * @param tableName
     * @param expertBase
     * @param reason
     * @return
     */

    public static LeaderCheckWithBLOBs verifier1DeleteDisagree(Object oldData, String tableName, ExpertBase expertBase, String reason) {
        LeaderCheckWithBLOBs leaderCheckWithBLOBs = verifier1Delete(oldData, tableName, expertBase);
        leaderCheckWithBLOBs.setWorkFlowStep(ShortData.s5);
        leaderCheckWithBLOBs.setWorkFlowStop(ShortData.s1);
        leaderCheckWithBLOBs.setOperateResult(ShortData.s0);
        leaderCheckWithBLOBs.setOperateReason(reason);
        return leaderCheckWithBLOBs;
    }


    /**
     * 部门领导（二级审核人）审核通过
     *
     * @param leaderCheck
     */
    public static void verifier2CheckTrue(LeaderCheck leaderCheck) {
        leaderCheck.setWorkFlowStep(ShortData.s3);

        Account acc = (Account) SecurityUtils.getSubject().getPrincipal();
        leaderCheck.setVerifier2Id(acc.getStaffInfo().getId());
        leaderCheck.setVerifier2IdCard(acc.getStaffInfo().getIdCard());
        leaderCheck.setVerifier2Name(acc.getStaffInfo().getName());
        leaderCheck.setVerifier2OperateDate(new Date());
    }

    /**
     * 部门领导（二级审核人）审核不通过
     *
     * @param leaderCheck
     * @param reason
     */
    public static void verifier2CheckFalse(LeaderCheck leaderCheck, String reason) {

        verifier2CheckTrue(leaderCheck);
        leaderCheck.setWorkFlowStep(ShortData.s4);
        leaderCheck.setWorkFlowStop(ShortData.s2);
        leaderCheck.setOperateResult(ShortData.s0);
        leaderCheck.setOperateReason(reason);

    }

    /**
     * 中心领导（三级审核人）审核通过
     *
     * @param leaderCheck
     */
    public static void verifier3CheckTrue(LeaderCheck leaderCheck) {
        leaderCheck.setWorkFlowStep(ShortData.s5);
        leaderCheck.setOperateResult(ShortData.s1);
        Account acc = (Account) SecurityUtils.getSubject().getPrincipal();
        leaderCheck.setVerifier3Id(acc.getStaffInfo().getId());
        leaderCheck.setVerifier3IdCard(acc.getStaffInfo().getIdCard());
        leaderCheck.setVerifier3Name(acc.getStaffInfo().getName());
        leaderCheck.setVerifier3OperateDate(new Date());
    }


    /**
     * 中心领导（三级审核人）审核不通过
     *
     * @param leaderCheck
     * @param reason
     */
    public static void verifier3CheckFalse(LeaderCheck leaderCheck, String reason) {
        verifier3CheckTrue(leaderCheck);
        leaderCheck.setWorkFlowStep(ShortData.s4);
        leaderCheck.setWorkFlowStop(ShortData.s3);
        leaderCheck.setOperateResult(ShortData.s0);
        leaderCheck.setOperateReason(reason);
    }


    /**
     * 处理  核查不同意
     *
     * @param leaderCheck
     */
    public static void handleCheckResult(LeaderCheck leaderCheck) {
        leaderCheck.setWorkFlowStep(ShortData.s5);
    }

}
